﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI;

namespace CustomControl
{
    
    public class MyServerControl : WebControl 
    {
        public string Tag { get; set; }
        [Category("Content")]
        [Description("Lotto numbers")]
        public string Numbers { get; set; }
        public string Draw { get; set; }


        public MyServerControl()
            : base("div")
        {
        }

        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
            base.RenderContents(writer);

            string[] numbers = Numbers.Split(',');
            string[] draw = Draw.Split(',');
            if ((numbers.Length == draw.Length) && (numbers.Length + draw.Length == 14))
            {
                int result = 0;
                for (int i = 0; i < numbers.Length; i++)
                {
                    writer.WriteBeginTag("span");
                    for (int n = 0; n < draw.Length; n++) {
                        if (numbers[i] == draw[n])
                        {
                            writer.WriteAttribute("class", "winningNumber");
                            result++;
                        }
                    }
                    writer.Write(HtmlTextWriter.TagRightChar);
                    writer.Write(numbers[i]);
                    writer.WriteEndTag("span");
                }
            }
            else
            {
                writer.Write("Angiv venligst 7 tal, samt 7 vindertal");
            }
        }

        public string GenerateRandomNumbers()
        {
            List<int> lottoNumbers = new List<int>();
            for (int i = 1; i < 37; i++)
            {
                lottoNumbers.Add(i);
            }
            string nbrs = "";
            int seed = 35;

            int max = 7;
            //while (max >= 0) {
                for (int i = 0; i < 7; i++)
                {
                    int rnd = RandomNumber(0, seed);
                    int picked = lottoNumbers[rnd];
                    lottoNumbers.Remove(rnd);
                    nbrs += picked.ToString();
                    seed--;
                    nbrs += "-------------";
                }
                
               // max--;
            //}
            return nbrs;

        }
        private int RandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max);
        }

    }

}